#pragma once
#ifndef FILEACCESS_H
#define FILEACCESS_H


#include <fstream>
#include <stdint.h>

enum SignalStatus
{
	Awaiting,
	Active,
	Inactive
};

class FileAccess
{
public:

	//size_t ===============================================================================
	
	static size_t Read_size_t(std::ifstream& Stream)
	{
		typedef uint32_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		return static_cast<size_t>(Buffer);
	}
	
	static void ReadByRef(std::ifstream& Stream, size_t &Data)
	{
		typedef uint32_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<size_t>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, size_t &Data)
	{
		typedef uint32_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}
	
	//float ===============================================================================

	static void ReadByRef(std::ifstream& Stream, float &Data)
	{
		typedef float BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<float>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, float &Data)
	{
		typedef float BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}


	//double ===============================================================================

	static void ReadByRef(std::ifstream& Stream, double &Data)
	{
		typedef double BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<double>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, double &Data)
	{
		typedef double BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}


	//signal Status ===============================================================================
	static void ReadByRef(std::ifstream& Stream, SignalStatus &Data)
	{
		typedef uint16_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<SignalStatus>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, SignalStatus &Data)
	{
		typedef uint16_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}

	//char ===============================================================================
	static char Read_char(std::ifstream& Stream)
	{
		typedef char BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		return Buffer;
	}

	static void ReadByRef(std::ifstream& Stream, char &Data)
	{
		typedef char BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<unsigned char>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, char &Data)
	{
		typedef char BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}

	//uint64_t  ===============================================================================
	/*static void ReadByRef(std::ifstream& Stream, uint64_t &Data)
	{
		typedef uint64_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<BufferType>(Buffer);
	}*/

	static uint64_t Read_uint64_t(std::ifstream& Stream)
	{
		typedef uint64_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		return static_cast<BufferType>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, const uint64_t &Data)
	{
		typedef uint64_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}

	//uint32_t  ===============================================================================
	/*static void ReadByRef(std::ifstream& Stream, uint32_t &Data)
	{
		typedef uint32_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<uint32_t>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, const uint32_t &Data)
	{
		typedef uint32_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}*/

	//uint16_t  ===============================================================================
	static void ReadByRef(std::ifstream& Stream, uint16_t &Data)
	{
		typedef uint16_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<BufferType>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, const uint16_t &Data)
	{
		typedef uint16_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}
	/*
	//int32_t  int32_t
	static void ReadByRef(std::ifstream& Stream, int32_t &Data)
	{
		typedef int32_t BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		Data = static_cast<int32_t>(Buffer);
	}

	static void WriteByRef(std::ofstream& Stream, const int32_t &Data)
	{
		typedef int32_t BufferType;
		BufferType Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}*/


	//uint16_t  ===============================================================================
	static void ReadByRef(std::ifstream& Stream, bool &Data)
	{
		typedef char BufferType;
		BufferType Buffer = 0;
		Stream.read((char *)(&Buffer), sizeof(BufferType));
		if (static_cast<BufferType>(Buffer) > 0)
			Data = true;
		else 
			Data = false;
	}

	static void WriteByRef(std::ofstream& Stream, const bool &Data)
	{
		typedef char BufferType;
		BufferType Buffer = 0;
		if (Data == true)
			Buffer = 1;
		else
			Buffer = 0;
		Buffer = static_cast<BufferType>(Data);
		Stream.write((char *)(&Buffer), sizeof(BufferType));
	}


};


//unsigned char ===============================================================================
/*static void ReadByRef(std::ifstream& Stream, unsigned char &Data)
{
typedef unsigned char BufferType;
BufferType Buffer = 0;
Stream.read((char *)(&Buffer), sizeof(BufferType));
Data = static_cast<unsigned char>(Buffer);
}

static unsigned char Read_unsigned_char(std::ifstream& Stream)
{
typedef unsigned char BufferType;
BufferType Buffer = 0;
Stream.read((char *)(&Buffer), sizeof(BufferType));
return Buffer;
}

static void WriteByRef(std::ofstream& Stream, unsigned char &Data)
{
typedef uint16_t BufferType;
BufferType Buffer = static_cast<BufferType>(Data);
Stream.write((char *)(&Buffer), sizeof(BufferType));
}*/// alles fehlerhafte funktionen


#endif